package com.csun.cmny.provider.controller;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.OmcReturnFeeConfig;
import com.csun.cmny.provider.model.dto.ReturnFeeConfigDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcReturnFeeConfigService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/returnFeeConfig", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcReturnFeeConfigController extends BaseController {

    @Resource
    private OmcReturnFeeConfigService omcReturnFeeConfigService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 保存
     * @param: [returnFeeConfigDto]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @PostMapping(value = "/save")
    public Wrapper saveReturnFeeConfig(@RequestBody ReturnFeeConfigDto returnFeeConfigDto) {

        int result = omcReturnFeeConfigService
                .saveReturnFeeConfig(convert(returnFeeConfigDto),getLoginAuthDto());

        //return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null),result);
    }

    /**
     * 查询
     * @param: [groupId]
     * @return: com.csun.cmny.util.wrapper.Wrapper
     */
    @PostMapping(value = "/getByGroupId/{groupId}")
    public Wrapper saveDaysTimeConfig(@PathVariable Long groupId) {

        OmcReturnFeeConfig omcReturnFeeConfig = omcReturnFeeConfigService
                .selectByGroupId(groupId);

        //return WrapMapper.ok(omcReturnFeeConfig);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), omcReturnFeeConfig);
    }

    /**
     * 转化
     * @param: [returnFeeConfigDto]
     * @return: com.csun.cmny.provider.model.domain.OmcReturnFeeConfig
     */
    public OmcReturnFeeConfig convert(ReturnFeeConfigDto returnFeeConfigDto){
        OmcReturnFeeConfig omcReturnFeeConfig = new OmcReturnFeeConfig();
        BeanUtils.copyProperties(returnFeeConfigDto,omcReturnFeeConfig);
        return omcReturnFeeConfig;
    }
}
